﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkflowCore.Persistence.EntityFramework.Models;
using WorkflowCore.Persistence.EntityFramework.Services;
using Yuekao.Domain.Entitys;

namespace Yuekao.Domain
{
    public class WorkflowContext : WorkflowDbContext
    {
        public DbSet<RoleModel> RoleModels {  get; set; }
        public DbSet<UserModel> UserModels { get; set; }
        public DbSet<WorkflowInstanceModel> WorkflowInstanceModels { get; set; }
        public DbSet<WorkflowDefinitionModel> WorkflowDefinitionModels { get; set; }
        public DbSet<AuditModel> AuditModels { get; set; }
        public DbSet<PersistedEvent> Event { get; set; }
        public DbSet<PersistedExecutionError> ExecutionError { get; set; }
        public DbSet<PersistedExecutionPointer> ExecutionPointer { get; set; }
        public DbSet<PersistedExtensionAttribute> ExtensionAttribute { get; set; }
        public DbSet<PersistedScheduledCommand> ScheduledCommand { get; set; }
        public DbSet<PersistedSubscription> Subscription { get; set; }
        public DbSet<PersistedWorkflow> Workflow { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySql("server=59.110.123.186;uid=root;pwd=GzcRen0303;database=WorkflowCore;", new  MySqlServerVersion("5.7"));
        }
        protected override void ConfigureEventStorage(EntityTypeBuilder<PersistedEvent> builder)
        {
            builder.ToTable("Event");
        }

        protected override void ConfigureExecutionErrorStorage(EntityTypeBuilder<PersistedExecutionError> builder)
        {
            builder.ToTable("ExecutionError");
        }

        protected override void ConfigureExecutionPointerStorage(EntityTypeBuilder<PersistedExecutionPointer> builder)
        {
            builder.ToTable("ExecutionPointer");
        }

        protected override void ConfigureExetensionAttributeStorage(EntityTypeBuilder<PersistedExtensionAttribute> builder)
        {
            builder.ToTable("ExtensionAttribute");
        }

        protected override void ConfigureScheduledCommandStorage(EntityTypeBuilder<PersistedScheduledCommand> builder)
        {
            builder.ToTable("ScheduledCommand");
        }

        protected override void ConfigureSubscriptionStorage(EntityTypeBuilder<PersistedSubscription> builder)
        {
            builder.ToTable("Subscription");
        }

        protected override void ConfigureWorkflowStorage(EntityTypeBuilder<PersistedWorkflow> builder)
        {
            builder.ToTable("Workflow");
        }
    }
}
